package com.han.gift.common.exception.ass;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.han.gift.common.exception.BusinessException;
import com.han.gift.common.exception.Erroenum.ErrorCode;
import org.apache.commons.lang3.StringUtils;


/**
 * @Author:Han
 * @Date :2023/2/27 18:01
 * @Description:
 */


//断言 业务判断
public class GiftAssert {
    public static void assertEqual(String str1,String str2,int code,String message){
        if(StringUtils.isEmpty(str1)|| StringUtils.isEmpty(str2)){
            throw new BusinessException(message,code);
        }
        if (!str1.trim().equals(str2.trim()))
            throw new BusinessException(message,code);
    }

    public static void assertEqual(String str1, String str2, ErrorCode code){
        if(StringUtils.isEmpty(str1)|| StringUtils.isEmpty(str2)){
            throw new BusinessException(code.getMessage(),code.getCode());
        }
        if (!str1.trim().equals(str2.trim()))
            throw new BusinessException(code.getMessage(),code.getCode());
    }

    public static void assertObjectIsNull(Object o,ErrorCode code){

        if(ObjectUtil.isNotNull(o)){
            throw new BusinessException(code.getMessage(),code.getCode());
        }

    }

    public static void assertObjectIsNotNull(Object o,ErrorCode code){

        if(ObjectUtil.isNull(o)){
            throw new BusinessException(code.getMessage(),code.getCode());
        }

    }



}
